//
//  ForeignStudyViewController.m
//  AoJi
//
//  Created by MinwenYi on 15-1-27.
//  Copyright (c) 2015年 xuanheng. All rights reserved.
//

#import "ForeignStudyViewController.h"
#import "SingleImageTableViewCell.h"
#import "DoubleImageTableViewCell.h"
#import "ActivityTableViewCell.h"
#import "DataSingleTon.h"
#import "SignUpView.h"

#import "DetailWebViewController.h"

#import "ChooseCountryViewController.h"
#import "AppDelegate.h"

#define kInterval 0.5
const static  int  secSegItemWidth=60;
@interface ForeignStudyViewController ()<UITableViewDataSource,UITableViewDelegate,CustomImageViewDelegate>
{
 
    
    BOOL isHeaderRefresh;
    
    //热点活动
    int countryId;
    int cityId;
    int lastId;
    
    //热点面试
    int interCountryId;
    int interCityId;
    
    //留学资讯
    int lastBtnInfo;
    NSMutableArray *countryNameSegItem;
    UIView *moreCountryView;//弹出视图
    NSMutableArray *itemArray;//留学资讯弹出的国家
    UIButton *moreBtn;//留学资讯
    
    
    
    UIView *sectionView;//顶部四项
    
    
    UIView      *activityView;
    UIView      *interviewView;
    UIView      *informationview;

    NSMutableArray *btnArray;
    
    int swipIndex;//切换视图
    
    NSMutableArray *countryListArray;//国家列表
    NSMutableArray *cityListArray;//城市列表
    NSMutableArray *activityArray;//热点活动
    NSMutableArray *interviewArray;//热点面试
    NSMutableArray *informationArray;//留学咨讯
    
    NSMutableDictionary *colordic;
    NSMutableDictionary *Imagedic;
    float selectCuntryHeight;
    
    
   
    UIView *popviewBg;
    UITableView *popTableview;
    UIButton *lastSelectedBtn;
    NSMutableArray *popViewData;
    
    //热点活动
    UILabel *countryNameLabel;
    UIButton *countryBtn;
    UILabel *cityName;
    UIButton *cityBtn;
    
    //热点面试
    UILabel *interviewCountryNameLabel;
    UIButton *interviewCountryBtn;
    UILabel *interviewCityName;
    UIButton *interviewCityBtn;
    
    
    UITableView *countryTableview;      //选择国家
    UITableView *activityTableView;     //热点活动
    UITableView *interViewTableview;    //热点面试
    UITableView *informationTableview; //留学咨讯
    
    UIScrollView *namesScrollview;//国家名字
    
    

    int consultIndex;
    
    
    
    UIView *sinUpBgView;
    SignUpView*  signUpview;
    
    NSMutableArray *informationTableviewArray;//留学资讯
    //
    UIScrollView *baseScrollview;

    
    int showIndex;
}

-(void)getInterviewData;//热点面试
@end

@implementation ForeignStudyViewController


-(void)nslogKeyboardHeight:(NSNotification*)notify
{
   
    NSString *language=[[UITextInputMode currentInputMode] primaryLanguage];
    
    NSDictionary *dic=[notify userInfo];
    CGSize kbSize=[[dic objectForKey:UIKeyboardFrameEndUserInfoKey]CGRectValue].size;
    
    

    NSLog(@"nslogKeyboardHeight==%.2f;language==%@",kbSize.height,language);

}
- (void)viewDidLoad {

    
//    NSMutableArray *countryListArray;//国家列表
//    NSMutableArray *cityListArray;//城市列表
//    NSMutableArray *activityArray;//热点活动
//    NSMutableArray *interviewArray;//热点面试
    
    activityArray=[NSMutableArray array];
    interviewArray=[NSMutableArray array];
    informationArray=[NSMutableArray array];
   
    
    
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(nslogKeyboardHeight:) name:UIKeyboardDidChangeFrameNotification object:nil];
    
    sinUpBgView=nil;
    
    
    countryListArray=[NSMutableArray array];
    countryListArray=[DataSingleTon shareDataSingleTon].countryList;
    
    cityListArray=[NSMutableArray array];
    cityListArray=[DataSingleTon shareDataSingleTon].cityList;
    
    NSArray *countryName=[NSArray arrayWithObjects: @"美国",@"英国", @"澳洲",@"加拿大", @"新西兰", @"欧洲",@"亚洲", nil];
    
    NSMutableArray *  countryImageArray=[NSMutableArray arrayWithObjects:@"meiguo.png",@"yingguo",@"aodaliya.png",
                       @"jiananda.png",@"xinxilan.png",@"ozhou.png",@"yazhou.png",
                       nil];
    
    
    
    NSMutableArray *  colorsArray=[NSMutableArray arrayWithObjects:
                 [self getCorlor:@"ea6745"],[self getCorlor:@"4bb799"],[self getCorlor:@"e85043"],// 美 英 澳大利亚
                 [self getCorlor:@"ad9fcc"],[self getCorlor:@"f0c95e"],[self getCorlor:@"e95874"],//加 新 欧洲 亚洲
                 [self getCorlor:@"78a7d9"],nil];
    
    
    
    Imagedic=[NSMutableDictionary dictionaryWithObjects:countryImageArray forKeys:countryName];
    
    colordic=[NSMutableDictionary dictionaryWithObjects:colorsArray forKeys:countryName];
    
    [super viewDidLoad];
    
    kBlackContent;
    
    self.ctitleLabel.text=@"出国留学";
    
    sectionView=[[UIView alloc]initWithFrame:CGRectMake(0, self.headerHeight, MainHeight, 42)];
    sectionView.backgroundColor=kheadBgcolor;
    
    [self.view addSubview:sectionView];
    float itemWidth=(Mainwidth-3)/4;
    
    NSArray *strs=[NSArray arrayWithObjects:@"选择国家",@"热点活动",@"热点面试",@"留学资讯", nil];
    btnArray=[NSMutableArray array];
    for (int i=0; i<4; i++) {
        UIButton *barBtn=[[UIButton alloc]initWithFrame:CGRectMake(1.5+itemWidth*i, 2.5, itemWidth, 40)];
        if (i==0) {
             barBtn.selected=YES;
        }
        
        barBtn.titleLabel.font=kFirstSegFontNum;
        [barBtn setTitle:strs[i] forState:UIControlStateNormal];
        [barBtn setTitleColor:[self getCorlor:@"646464"] forState:UIControlStateNormal];
        [barBtn setTitleColor:[self getCorlor:@"e70012"] forState:UIControlStateSelected];
        barBtn.tag=i;
        [sectionView addSubview:barBtn];
        [barBtn addTarget:self action:@selector(clickTheBarBtn:) forControlEvents:UIControlEventTouchUpInside];
        [btnArray addObject:barBtn];
    }
    
    for (int i=0; i<3; i++) {
        UIView *yLabel=[[UIView  alloc]initWithFrame:CGRectMake(1.5+itemWidth*(i+1), 6, 1, 30)];
        yLabel.backgroundColor=[UIColor colorWithPatternImage:[UIImage imageNamed:@"forginStudyfengjiexian-y.png"]];
        [sectionView addSubview:yLabel];
        
        
    }
    
    
    
    UIView *topLineview=[[UIView alloc]initWithFrame:CGRectMake(0,2, Mainwidth, 1)];
    topLineview.backgroundColor=[UIColor colorWithPatternImage:[UIImage imageNamed:@"fengjiexian-x.png"]];
    [sectionView addSubview:topLineview];
    
    UIView *bottomLineview=[[UIView alloc]initWithFrame:CGRectMake(0, viewHeight(sectionView)-1, Mainwidth, 1)];
    [sectionView addSubview:bottomLineview];
    bottomLineview.backgroundColor=[UIColor colorWithPatternImage:[UIImage imageNamed:@"fengjiexian-x.png"]];
    

       
    
    baseScrollview=[[UIScrollView alloc]initWithFrame:CGRectMake(0, viewBottom(sectionView), Mainwidth, MainHeight-viewBottom(sectionView))];
    
    
    baseScrollview.delegate=self;
    baseScrollview.showsVerticalScrollIndicator=NO;
    baseScrollview.pagingEnabled=YES;
    baseScrollview.contentSize=CGSizeMake(Mainwidth*4, 0);
    
    [self.view addSubview:baseScrollview];
    
    [self initSelectCuntry];
    
    
     [self initViews];
    

    
    // Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark 选择国家
-(void)initSelectCuntry
{
    countryTableview=[[UITableView alloc]initWithFrame:CGRectMake(0,0, Mainwidth,viewHeight(baseScrollview)-6) style:UITableViewStylePlain];
    countryTableview.bounces=NO;
     selectCuntryHeight=CGRectGetHeight(countryTableview.bounds)/4;
    
    
    countryTableview.separatorStyle=UITableViewCellSeparatorStyleNone;
    countryTableview.dataSource=self;
    countryTableview.delegate=self;
    baseScrollview.backgroundColor=[UIColor whiteColor];
    [baseScrollview addSubview:countryTableview];


}
-(void)initViews
{

    activityView=[[UIView alloc]initWithFrame:CGRectMake(Mainwidth,0, Mainwidth, viewHeight(baseScrollview))];
   
    
    interviewView=[[UIView alloc]initWithFrame:CGRectMake(Mainwidth*2,0, Mainwidth, viewHeight(baseScrollview))];

    informationview=[[UIView alloc]initWithFrame:CGRectMake(Mainwidth*3, 0, Mainwidth,viewHeight(baseScrollview))];
    
    
    [baseScrollview addSubview:activityView];
    [baseScrollview addSubview:informationview];
    [baseScrollview addSubview:interviewView];

    [self getActivityData];
    
    [self dealActivityView];
    
    [self dealInterView];
    [self dealInformationview];
    
    [baseScrollview addObserver:self forKeyPath:@"contentOffset" options:NSKeyValueObservingOptionNew|NSKeyValueObservingOptionOld context:nil];
}

#pragma mark  热点活动

-(void)getActivityData//热点活动
{
    
    
    //study/activity?countryid=xx&cityid=xx
    
    
    NSMutableDictionary *param=[NSMutableDictionary dictionary];
    
    
    
    if (self.requestType==typeFooterRefresh) {
        lastId=   [[[activityArray lastObject] objectForKey:@"id"]intValue];
        [param setObject:@(lastId)  forKey:@"lastid"];
    }
    
    if (cityId!=0) {
        id inte=   cityListArray[cityId-1];
        [param setObject:[cityListArray[cityId-1] objectForKey:@"id"]  forKey:@"cityid"];
    }
    
    if (countryId!=0) {
        id inte=countryListArray[countryId-1];
        [param setObject:[countryListArray[countryId-1] objectForKey:@"id"]  forKey:@"countryid"];
    }
    
    
    
    [YHNetwork getInformationWithReguestType:RequestTypeGet WithParameters:param WithApi:@"study/activity" WhenSuccess:^(NSMutableDictionary *response) {
        
        
        if (self.requestType==typeHeaderRefresh) {
            [activityArray removeAllObjects];
        }
        
        for (NSDictionary* tem in response) {
            [activityArray addObject:tem];
        }
        if (self.requestType==typeHeaderRefresh) {
            [activityTableView headerEndRefreshing];
        }else if (self.requestType==typeFooterRefresh)
        {
            
            [activityTableView footerEndRefreshing];
            
        }
        [activityTableView reloadData];
       
    } WhenFailure:^(NSError *failure) {
        if (self.requestType==typeHeaderRefresh) {
            [activityTableView headerEndRefreshing];
        }else if (self.requestType==typeFooterRefresh)
        {
            [activityTableView headerEndRefreshing];
            [activityTableView footerEndRefreshing];
            
        }
    }];
    
}

-(void)dealActivityView
{
    UIView *headerView=[[UIView alloc]initWithFrame:CGRectMake(0, 0, Mainwidth, 50)];
    
    
    UIView *yLine=[[UIView alloc]initWithFrame:CGRectMake(Mainwidth/2-0.5, 3, 1, 46)];
    [headerView addSubview:yLine];
    yLine.backgroundColor=[UIColor colorWithPatternImage:[UIImage imageNamed:@"forginStudyfengjiexian-y.png"]];
    
    UIView *xLine=[[UIView alloc]initWithFrame:CGRectMake(0, 49, Mainwidth, 1)];
    [headerView addSubview:xLine];
    xLine.backgroundColor=[UIColor colorWithPatternImage:[UIImage imageNamed:@"fengjiexian-x.png"]];
    
    
    
    
    
    
    
    
    
    
    headerView.backgroundColor=kheadBgcolor;
    headerView.tag=101;
    [activityView addSubview:headerView];
    countryNameLabel=[[UILabel alloc]initWithFrame:CGRectMake(30, 0,100, 50)];
    countryNameLabel.tag=0;
    NSMutableAttributedString *atts=[[NSMutableAttributedString alloc]initWithString:@"国家:请选择"];
    [atts addAttributes:@{
                         NSFontAttributeName:[UIFont systemFontOfSize:12],
                         NSForegroundColorAttributeName:[self getCorlor:@"888888"],
                         
                         
                         } range:NSMakeRange(0, 3)];
    [atts addAttributes:@{
                          NSFontAttributeName:[UIFont systemFontOfSize:12],
                          NSForegroundColorAttributeName:[self getCorlor:@"444444"],
                          
                          
                          } range:NSMakeRange(3, atts.length-3)];
    
    countryNameLabel.attributedText=atts;
    [headerView addSubview:countryNameLabel];
    
    countryBtn=[[UIButton alloc]initWithFrame:CGRectMake(100, 0, 50, 50)];
    countryBtn.imageEdgeInsets = UIEdgeInsetsMake(1, 5, 0, 0);
    [headerView addSubview:countryBtn];
    
    [countryBtn setImage:[UIImage imageNamed:@"jiantouxiaActivity.png"] forState:UIControlStateNormal];
    [countryBtn setImage:[UIImage imageNamed:@"jiantoushangActivity.png"] forState:UIControlStateSelected];
    [countryBtn addTarget:self action:@selector(tapTheSelectBtn:) forControlEvents:UIControlEventTouchUpInside];
    
    
    //jiantoushangActivity.png
    
    cityName=[[UILabel alloc]initWithFrame:CGRectMake(180, 0,150, 50)];
    NSMutableAttributedString *atts1=[[NSMutableAttributedString alloc]initWithString:@"分公司:请选择"];
    [atts1 addAttributes:@{
                          NSFontAttributeName:[UIFont systemFontOfSize:12],
                          NSForegroundColorAttributeName:[self getCorlor:@"888888"],
                          
                          
                          } range:NSMakeRange(0, 4)];
    [atts1 addAttributes:@{
                          NSFontAttributeName:[UIFont systemFontOfSize:12],
                          NSForegroundColorAttributeName:[self getCorlor:@"444444"],
                          
                          
                          } range:NSMakeRange(3, atts1.length-3)];
    
    cityName.attributedText=atts1;
    [headerView addSubview:cityName];
    
    cityBtn=[[UIButton alloc]initWithFrame:CGRectMake(260, 0, 50, 50)];
    [headerView addSubview:cityBtn];
    cityBtn.imageEdgeInsets = UIEdgeInsetsMake(1, 5, 0, 0);
    
    [cityBtn setImage:[UIImage imageNamed:@"jiantouxiaActivity.png"] forState:UIControlStateNormal];
    [cityBtn setImage:[UIImage imageNamed:@"jiantoushangActivity.png"] forState:UIControlStateSelected];
    [cityBtn addTarget:self action:@selector(tapTheSelectBtn:) forControlEvents:UIControlEventTouchUpInside];
    cityBtn.tag=1;
    activityTableView=[[UITableView alloc]initWithFrame:CGRectMake(0, viewHeight(headerView), Mainwidth, viewHeight(activityView)-viewHeight(headerView)) style:UITableViewStylePlain];
    activityTableView.separatorStyle=UITableViewCellSeparatorStyleSingleLine;
    
    [activityTableView registerClass:[ActivityTableViewCell class] forCellReuseIdentifier:@"cell"];
    activityTableView.showsVerticalScrollIndicator=NO;
    activityTableView.dataSource=self;
    activityTableView.delegate=self;
    activityTableView.tableFooterView=[[UIView alloc]initWithFrame:CGRectZero];
    
    [activityView addSubview:activityTableView];
    
    [activityTableView addHeaderWithCallback:^{
        self.requestType=typeHeaderRefresh;
        [self getActivityData];
        
    }];
    [activityTableView addFooterWithCallback:^{
        self.requestType=typeFooterRefresh;
        [self getActivityData];
    }];
    
    
    
}


-(void)tapTheSelectBtn:(UIButton*)sender
{
    
    
    
    if (popviewBg==nil) {
        popviewBg=[[UIView alloc]initWithFrame:CGRectMake(0, 50, Mainwidth, viewHeight(activityView)-50)];
        popviewBg.backgroundColor=[UIColor colorWithRed:0/255.0 green:0/255.0 blue:0/255.0 alpha:0.5];
        popTableview=[[UITableView alloc]initWithFrame:CGRectMake(0,0,Mainwidth, viewHeight(popviewBg)-150) style:UITableViewStylePlain];
        popTableview.backgroundColor=[UIColor clearColor];
        
        popTableview.tableHeaderView=[[UIView alloc]initWithFrame:CGRectZero];
        [popTableview registerClass:[SingleImageTableViewCell class] forCellReuseIdentifier:@"cell"];
        popTableview.dataSource=self;
        popTableview.delegate=self;
        popTableview.bounces=NO;
        popTableview.showsVerticalScrollIndicator=NO;
        [popviewBg addSubview:popTableview];
        
    }
    
    
    
    if (sender!=lastSelectedBtn) {
        lastSelectedBtn.selected=NO;
    }
    
    if (sender.selected!=YES) {
        sender.selected=YES;
        lastSelectedBtn=sender;
        if (sender.tag==0) {
            NSLog(@"==0");
            popViewData=[DataSingleTon shareDataSingleTon].countryList;
        }else{
            NSLog(@"==1");
            popViewData=[DataSingleTon shareDataSingleTon].cityList;
        }
        
        [popTableview reloadData];
        
        if (swipIndex==2) {
    
            
            [interviewView addSubview:popviewBg];
            
            
            UIView *temview=[interviewView viewWithTag:101];
            [interviewView bringSubviewToFront:temview];
        }else{
          [activityView addSubview:popviewBg];
            
            UIView *temview=[activityView viewWithTag:101];
            [activityView bringSubviewToFront:temview];
        
        }
      
        
    }else{
        sender.selected=NO;
        [popviewBg removeFromSuperview];
    
    }

}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

-(void)clickTheBarBtn:(UIButton *)sender
{
    
    if (sender.tag!=swipIndex)
    {
        
        baseScrollview.contentOffset=CGPointMake(sender.tag*Mainwidth, 0);
        
        UIButton *temBtn=btnArray[swipIndex];
        temBtn.selected=NO;
        swipIndex=(int)sender.tag;
        UIButton *temBtn1=btnArray[swipIndex];
        temBtn1.selected=YES;
    }
    

}





//选择国家
-(void)tapTheBgbiew:(UIGestureRecognizer*)tap
{
    NSLog(@"tap==%i",(int)[tap view].tag);
    
    
        ChooseCountryViewController *chooseVc=[[ChooseCountryViewController alloc]init];

    chooseVc.tagId=(int)[tap view].tag;
    [self.navigationController pushViewController:chooseVc animated:YES];
    
    



}

-(void)tapTheCustomImage:(CustomImageView*)imgeview
{
    NSLog(@"IMGTAP==%i",imgeview.tag);
    ChooseCountryViewController *chooseVc=[[ChooseCountryViewController alloc]init];
    
    chooseVc.tagId=imgeview.tag;
    [self.navigationController pushViewController:chooseVc animated:YES];
    
    

}

#pragma mark 热点面试
-(void)getInterviewData//热点面试
{
    
    //    study/lecture?countryid=xx&cityid
    
    NSMutableDictionary *param=[NSMutableDictionary dictionary];
    
    
    
    if (interCityId!=0) {
      
        [param setObject:[cityListArray[interCityId-1] objectForKey:@"id"]  forKey:@"cityid"];
    }
    
    if (interCountryId!=0) {
        
        [param setObject:[countryListArray[interCountryId-1] objectForKey:@"id"]  forKey:@"countryid"];
    }

    
    if (self.requestType==typeFooterRefresh) {
        lastId=   [[[interviewArray lastObject] objectForKey:@"id"]intValue];
        [param setObject:@(lastId)  forKey:@"lastid"];
    }

    
   



    [YHNetwork getInformationWithReguestType:RequestTypeGet WithParameters:param WithApi:@"study/lecture" WhenSuccess:^(NSMutableDictionary *response) {
        
//        interviewArray=response;
      
        if (self.requestType==typeHeaderRefresh) {
            [interviewArray removeAllObjects];
        }
        
        for (NSDictionary* tem in response) {
            [interviewArray addObject:tem];
        }
        if (self.requestType==typeHeaderRefresh) {
            [interViewTableview headerEndRefreshing];
        }else if (self.requestType==typeFooterRefresh)
        {
            [interViewTableview footerEndRefreshing];
            
        }
         [interViewTableview reloadData];
        
    } WhenFailure:^(NSError *failure) {
        if (self.requestType==typeHeaderRefresh) {
            [activityTableView headerEndRefreshing];
        }else if (self.requestType==typeFooterRefresh)
        {
            [interViewTableview headerEndRefreshing];
            [interViewTableview footerEndRefreshing];
            
            
        }
    }];

    
    
}


-(void)dealInterView//热点面试
{
    

    UIView *headerView2=[[UIView alloc]initWithFrame:CGRectMake(0, 0, Mainwidth, 50)];
    
    UIView *yLine=[[UIView alloc]initWithFrame:CGRectMake(Mainwidth/2-0.5, 3, 1, 46)];
    [headerView2 addSubview:yLine];
    yLine.backgroundColor=[UIColor colorWithPatternImage:[UIImage imageNamed:@"forginStudyfengjiexian-y.png"]];
    
    UIView *xLine=[[UIView alloc]initWithFrame:CGRectMake(0, 49, Mainwidth, 1)];
    [headerView2 addSubview:xLine];
    xLine.backgroundColor=[UIColor colorWithPatternImage:[UIImage imageNamed:@"fengjiexian-x.png"]];
    
    
    
    headerView2.backgroundColor=kheadBgcolor;
    [interviewView addSubview:headerView2];
    headerView2.tag=101;
    
   

    interviewCountryNameLabel=[[UILabel alloc]initWithFrame:CGRectMake(30, 0,100,50)];
    NSMutableAttributedString *atts=[[NSMutableAttributedString alloc]initWithString:@"国家:请选择"];
    [atts addAttributes:@{
                          NSFontAttributeName:[UIFont systemFontOfSize:12],
                          NSForegroundColorAttributeName:[self getCorlor:@"888888"],
                          
                          
                          } range:NSMakeRange(0, 3)];
    [atts addAttributes:@{
                          NSFontAttributeName:[UIFont systemFontOfSize:12],
                          NSForegroundColorAttributeName:[self getCorlor:@"444444"],
                          
                          
                          } range:NSMakeRange(3, atts.length-3)];
    
    interviewCountryNameLabel.attributedText=atts;
    [headerView2 addSubview:interviewCountryNameLabel];

    interviewCountryBtn=[[UIButton alloc]initWithFrame:CGRectMake(100, 0,50, 50)];
    [headerView2 addSubview:interviewCountryBtn];
    interviewCountryBtn.tag=0;
    
    [interviewCountryBtn setImage:[UIImage imageNamed:@"jiantouxiaActivity"] forState:UIControlStateNormal];
    [interviewCountryBtn setImage:[UIImage imageNamed:@"jiantoushangActivity.png"] forState:UIControlStateSelected];
    interviewCountryBtn.imageEdgeInsets = UIEdgeInsetsMake(1, 5, 0, 0);
    
    
    
    [interviewCountryBtn addTarget:self action:@selector(tapTheSelectBtn:) forControlEvents:UIControlEventTouchUpInside];
    
    
    //jiantoushangActivity.png
    
    interviewCityName=[[UILabel alloc]initWithFrame:CGRectMake(180, 0,150, 50)];
    NSMutableAttributedString *atts1=[[NSMutableAttributedString alloc]initWithString:@"分公司:请选择"];
    [atts1 addAttributes:@{
                           NSFontAttributeName:[UIFont systemFontOfSize:12],
                           NSForegroundColorAttributeName:[self getCorlor:@"888888"],
                           
                           
                           } range:NSMakeRange(0, 4)];
    [atts1 addAttributes:@{
                           NSFontAttributeName:[UIFont systemFontOfSize:12],
                           NSForegroundColorAttributeName:[self getCorlor:@"444444"],
                           
                           
                           } range:NSMakeRange(3, atts1.length-3)];
    
    interviewCityName.attributedText=atts1;
    [headerView2 addSubview:interviewCityName];
    
    interviewCityBtn=[[UIButton alloc]initWithFrame:CGRectMake(260, 0,50, 50)];
    [headerView2 addSubview:interviewCityBtn];
    
    
    [interviewCityBtn setImage:[UIImage imageNamed:@"jiantouxiaActivity.png"] forState:UIControlStateNormal];
    [interviewCityBtn setImage:[UIImage imageNamed:@"jiantoushangActivity.png"] forState:UIControlStateSelected];
    
    [interviewCityBtn setImageEdgeInsets:UIEdgeInsetsMake(1, 5, 0, 0)];
    interviewCityBtn.tag=1;
    
    [interviewCityBtn addTarget:self action:@selector(tapTheSelectBtn:) forControlEvents:UIControlEventTouchUpInside];
    
    interViewTableview=[[UITableView alloc]initWithFrame:CGRectMake(0, 50, Mainwidth, viewHeight(activityView)-50) style:UITableViewStylePlain];
    interViewTableview.separatorStyle=UITableViewCellSeparatorStyleSingleLine;
    
    [interViewTableview registerClass:[ActivityTableViewCell class] forCellReuseIdentifier:@"cell"];
    
    interViewTableview.showsVerticalScrollIndicator=NO;
    interViewTableview.dataSource=self;
    interViewTableview.delegate=self;
    
    [interViewTableview registerClass:[ActivityTableViewCell class] forCellReuseIdentifier:@"intervierviewcell"];
    
    interViewTableview.tableFooterView=[[UIView alloc]initWithFrame:CGRectZero];
    
    [interviewView addSubview:interViewTableview];
    
    
    [interViewTableview addHeaderWithCallback:^{
        self.requestType=typeHeaderRefresh;
        [self getInterviewData];
    }];
    [interViewTableview addFooterWithCallback:^{
        self.requestType=typeFooterRefresh;
        [self getInterviewData];
    }];
    
    [self getInterviewData];


}




/*
 "begin_time" = "-2140880400";
 "city_name" = "\U5185\U8499\U53e4";
 "company_id" = 30;
 "country_id" = 2;
 description = "\U3000\U3000\U6fb3\U5927\U5229\U4e9a\U7684\U6559\U80b2\U8d28\U91cf\U4eab\U8a89\U5168\U7403\Uff0c\U4f20\U627f\U81ea\U82f1\U56fd\U7684\U6559\U80b2\U4f53\U7cfb\Uff0c\U7ed3\U5408\U4e86\U6b27\U7f8e\U7684";
 "end_time" = 1425114000;
 "host_city" = 30;
 id = 6033;
 thumb = "http://img.aoji.cn/2015/0112/KL3fOkZCujGj.jpg";
 title = "\U65e0\U9ad8\U8003\U6210\U7ee9\U7533\U8bf7\U6fb3\U5927\U5229\U4e9a\U540d\U6821\U79d8\U7c4d";
 },
 
 */
#pragma mark 留学咨询
-(void)getInfomationData//留学咨询
{
    //    cent.dsgrd.com/study/news?ccode=us&lastid=0
    
    
    NSMutableDictionary *param=[NSMutableDictionary dictionary];
    
//    countryListArray;
    
    if (consultIndex!=0) {
        
        
//        catdir
            [param setObject:[countryListArray[consultIndex-1]  objectForKey:@"catdir"] forKey:@"ccode"];
    }
    
    
    if (self.requestType==typeFooterRefresh) {
         [param setObject:[[informationArray lastObject] objectForKey:@"id"] forKey:@"lastid"];
    }
    
    
    
    [YHNetwork getInformationWithReguestType:RequestTypeGet WithParameters:param WithApi:@"study/news" WhenSuccess:^(NSMutableDictionary *response) {
        if (self.requestType!=typeFooterRefresh) {
            [informationArray removeAllObjects];
        }
        
        for (NSDictionary* tem in response) {
            [informationArray addObject:tem];
        }
        if (self.requestType==typeHeaderRefresh) {
            [informationTableview headerEndRefreshing];
        }else if (self.requestType==typeFooterRefresh)
        {
            [informationTableview footerEndRefreshing];
            
        }
        [informationTableview reloadData];
        
    } WhenFailure:^(NSError *failure) {
        if (self.requestType==typeHeaderRefresh) {
            [informationTableview headerEndRefreshing];
        }else if (self.requestType==typeFooterRefresh)
        {
            [informationTableview footerEndRefreshing];
            
            
        }
    }];
    
    
   
    
}


-(void)dealInformationview
{
    namesScrollview=[[UIScrollView alloc]initWithFrame:CGRectMake(0,0, Mainwidth-50, 42)];
    namesScrollview.backgroundColor=kheadBgcolor;
    
    
    [informationview addSubview:namesScrollview];
    
    
    moreBtn=[[UIButton alloc]initWithFrame:CGRectMake(Mainwidth-50, 0, 50, 42)];
    moreBtn.backgroundColor=kheadBgcolor;
    
    [informationview addSubview:moreBtn];
    
    [moreBtn setImage:[UIImage imageNamed:@"gengduoxia@2x.png"] forState:UIControlStateNormal];
    [moreBtn setImage:[UIImage imageNamed:@"gengduoshang@2x.png"] forState:UIControlStateSelected];
    [moreBtn addTarget:self action:@selector(tapMoreBtn:) forControlEvents:UIControlEventTouchUpInside];
    
    UIView *shadowview=[[UIView alloc]initWithFrame:CGRectMake(viewLeft(moreBtn)-23/4, viewTop(moreBtn), 23/2, 50)];
    shadowview.backgroundColor=[UIColor colorWithPatternImage:[UIImage imageNamed:@"yingyin@2x.png"]];
    [informationview addSubview:shadowview];

    
    countryNameSegItem=[NSMutableArray array];
    
    for (int i=0; i<countryListArray.count+1; i++) {
        UIButton *item=[[UIButton alloc]initWithFrame:CGRectMake(60*i, 1, secSegItemWidth, 40)];
        [namesScrollview addSubview:item];
        if(i==0)
        {
            [item setTitle:@"全部" forState:UIControlStateNormal];
            item.selected=YES;
            lastBtnInfo=i;
            
            
        }else{
            [item setTitle:[countryListArray[i-1] objectForKey:@"name" ] forState:UIControlStateNormal];
            }
           item.tag=i;
        item.titleLabel.font=[UIFont systemFontOfSize:13];
        [item setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [item setTitleColor:[UIColor redColor] forState:UIControlStateSelected];
        
        [item addTarget:self action:@selector(tapTheInFormationItem:) forControlEvents:UIControlEventTouchUpInside];
        
        
        [countryNameSegItem addObject:item];
        
    }
    
    namesScrollview.contentSize=CGSizeMake((countryListArray.count+1)*60, 0);
    namesScrollview.showsHorizontalScrollIndicator=NO;
    UIView *bottomLine=[[UIView alloc]initWithFrame:CGRectMake(0, viewBottom(namesScrollview)-1, Mainwidth, 1)];
    bottomLine.backgroundColor=[UIColor colorWithPatternImage:[UIImage imageNamed:@"fengjiexian-x.png"]];
    [informationview addSubview:bottomLine];
    
    
    
        informationTableview=[[UITableView alloc]initWithFrame:CGRectMake(0,viewHeight(namesScrollview), Mainwidth,viewHeight(informationview)-viewHeight(namesScrollview)) style:UITableViewStylePlain];
        informationTableview.dataSource=self;
        informationTableview.delegate=self;
        informationTableview.showsVerticalScrollIndicator=NO;
        informationTableview.separatorStyle=UITableViewCellSelectionStyleNone;
        [informationview addSubview:informationTableview];
        [informationTableview registerClass:[ActivityTableViewCell class] forCellReuseIdentifier:@"cell"];
    
        [informationTableview addHeaderWithCallback:^{
            self.requestType=typeHeaderRefresh;
            [self getInfomationData];
        }];
    
    [informationTableview addHeaderWithCallback:^{
        self.requestType=typeHeaderRefresh;
        [self getInfomationData];
        
    }];
    [informationTableview addFooterWithCallback:^{
        self.requestType=typeFooterRefresh;
        [self getInfomationData];
    }];
    
    [self getInfomationData];
    
}

-(void)tapTheInFormationItem:(UIButton*)sender
{
    NSMutableArray *temArr=countryNameSegItem;
    
    
    if (sender.tag!=lastBtnInfo) {
        UIButton *temBtn=temArr[lastBtnInfo];
        temBtn.selected=NO;
        UIButton *temBtn1=temArr[sender.tag];
        temBtn1.selected=YES;
        UIScrollView *temScrollview=(UIScrollView*)[temBtn1 superview];
        int temcurr=(int)sender.tag;
        
        if (sender.tag>lastBtnInfo)
        {
            if ((temcurr+1)*secSegItemWidth+60>viewWidth(namesScrollview)) {
                int tem=(int)viewLeft(temBtn1)-2*secSegItemWidth>(int)temScrollview.contentSize.width-(int)viewWidth(temBtn1.superview)?temScrollview.contentSize.width-viewWidth(temScrollview):(int)sender.tag*secSegItemWidth-2*secSegItemWidth;
                temScrollview.contentOffset=CGPointMake(tem, 0);
            }
        
        }
        else if (sender.tag<lastBtnInfo)
        {
            if ((int)sender.tag*secSegItemWidth-60<temScrollview.contentOffset.x) {
                int tem=temcurr-2>0?temcurr-2:0;
                temScrollview.contentOffset=CGPointMake(tem*60, 0);
            }
            
        
        }

        lastBtnInfo=(int)sender.tag;
        consultIndex=(int)sender.tag;
        self.requestType=typeDefault;
        [self getInfomationData];
    }
    
}
-(void)tapMoreBtn:(UIButton*)sender
{
//242
    sender.selected=!sender.selected;
    
    if (sender.selected) {
        [self addMoreCountryView];
        
    }
    else{
    
        [self removeMoreCountryView];
    }
    
    
    
    

}

-(void)addMoreCountryView
{
    if (moreCountryView==nil)
    {
        
        itemArray=[NSMutableArray array];
        moreCountryView=[[UIView alloc]initWithFrame:CGRectMake(0, 42, Mainwidth, viewHeight(informationview)-42)];
        [informationview addSubview:moreCountryView];

        UIView *moreView=[[UIView alloc]initWithFrame:CGRectMake(0,0, Mainwidth, 100)];
        moreView.backgroundColor=[UIColor colorWithRed:242/255.0 green:244/255.0 blue:242/255.0 alpha:1];
        [moreCountryView addSubview:moreView];
        
        int rowNum=countryListArray.count+1%4==0?(countryListArray.count+1)/4:((countryListArray.count+1)/4+1);
        
        CGFloat itemWidth=Mainwidth/4;
        
        //gengduguojia.png
        
        
        
        for (int i=0; i<countryListArray.count+1; i++)
        {
            UILabel    *item=[[UILabel alloc]initWithFrame:CGRectMake(5+itemWidth*(i%4),40*(i/4)+10,itemWidth-10, 40)];
            
            
            
            [itemArray addObject:item];
            
            UIImageView *bgImgView=[[UIImageView alloc]initWithFrame:CGRectMake(5+itemWidth*(i%4),40*(i/4)+10,itemWidth-10, 40)];
            bgImgView.image=[UIImage imageNamed:@"gengduguojia.png"];
            [moreView addSubview:bgImgView];
            
            [moreView addSubview:item];
            if(i==0)
            {
                item.text=@"全部";
                
                
            }else{
                item.text=[countryListArray[i-1] objectForKey:@"name" ];
            }
            item.tag=i;
            UIGestureRecognizer *tap=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapCountryName:)];
            
            [item addGestureRecognizer:tap];
            item.userInteractionEnabled=YES;
            
            
            item.textAlignment=NSTextAlignmentCenter;
            item.font=[UIFont systemFontOfSize:13];
            //                       [item addTarget:self action:@selector(tapTheInFormationItem:) forControlEvents:UIControlEventTouchUpInside];
            
            
         
            
        }
        
        UIImage *shangHuaImg=[UIImage imageNamed:@"shanghua.png"];
        
        UIImageView *shangHua=[[UIImageView alloc]initWithFrame:CGRectMake(0, 100, Mainwidth, shangHuaImg.size.height*Mainwidth/shangHuaImg.size.width)];
        
        shangHua.contentMode=UIViewContentModeScaleAspectFit;
        shangHua.image=shangHuaImg;
        
        [moreCountryView addSubview:shangHua];

    }else{
    
    
        [informationview addSubview:moreCountryView];
    }
    
    

}


-(void)removeMoreCountryView
{
    moreBtn.selected=NO;
    [moreCountryView removeFromSuperview];
    
}
#warning 全部不选项展开
-(void)tapCountryName:(UIGestureRecognizer*)tap
{

    consultIndex=tap.view.tag;
    self.requestType=typeDefault;
//    [self getInfomationData];
    [self tapTheInFormationItem:tap.view];
    [self removeMoreCountryView];
    
    

}

#pragma mark tableviewdatasourceAndDelegate

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    
    
    if (tableView==countryTableview) {
        return (countryListArray.count-1)/2+1;
    }else if (tableView==activityTableView)
    {
        
        return activityArray.count;
        
    }
    else if (tableView==interViewTableview)
    {
        
        return interviewArray.count;
        
    }
    else if (tableView==popTableview)
    {
        
        return popViewData.count+1;
    }
    else if(tableView==informationTableview) //留学资讯
    {
        
        return informationArray.count;
    }
    else{
        return 0;
    }
    
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (tableView==countryTableview) {
        
        
        //    float cellheight=(CGRectGetHeight(countryTableview.bounds)-60)/5;
        if (indexPath.row==0) {
            SingleImageTableViewCell *cell=[[SingleImageTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil];
            cell.selectionStyle=UITableViewCellSelectionStyleNone;
            
            cell.titleLabel.frame=CGRectMake(Mainwidth/2, 6, Mainwidth/2, selectCuntryHeight-6);
            cell.titleLabel.textAlignment=NSTextAlignmentCenter;
//
            cell.singleImageview.delegate=self;
            cell.singleImageview.tag=0;
            NSString *countryName=[countryListArray[indexPath.row] objectForKey:@"name"];
            cell.titleLabel.text=countryName;
            cell.titleLabel.font=[UIFont systemFontOfSize:18];
            cell.titleLabel.textColor=[UIColor whiteColor];
  
            cell.bgView.frame=CGRectMake(13/2,6, Mainwidth-13, selectCuntryHeight-6);
            
            
            
            cell.bgView.backgroundColor=[colordic objectForKey:countryName];
            
            

            UIGestureRecognizer *tap=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapTheBgbiew:)];
            [cell.bgView addGestureRecognizer:tap];
            cell.bgView.tag=0;
            
            UIImage *temImg=[UIImage imageNamed:[Imagedic objectForKey:countryName]];
            
            cell.singleImageview.image=temImg;
            cell.singleImageview.frame=CGRectMake(0,13/2, temImg.size.width/2, temImg.size.height/2);
            
            CGPoint point=CGPointMake(cell.bgView.center.x-temImg.size.width/4, cell.bgView.center.y);
            cell.singleImageview.center=point;
            return cell;
        }else{
            
            int itemWidth=(Mainwidth-13-6)/2;
            
            DoubleImageTableViewCell *cell=[[DoubleImageTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil];
            
            cell.selectionStyle=UITableViewCellSelectionStyleNone;
            
            cell.firstLabel.frame=CGRectMake(13/2 ,selectCuntryHeight-32 ,itemWidth,20);
            cell.firstLabel.textAlignment=NSTextAlignmentCenter;
            cell.firstLabel.textColor=[UIColor whiteColor];
            cell.firstLabel.font=[UIFont systemFontOfSize:18];
            
            cell.secondLabel.frame=CGRectMake(12.5+itemWidth,selectCuntryHeight-32 ,itemWidth,20);
            cell.secondLabel.textAlignment=NSTextAlignmentCenter;
            cell.secondLabel.textColor=[UIColor whiteColor];
            cell.secondLabel.font=[UIFont systemFontOfSize:18];
            
            NSString *firstName=[countryListArray[indexPath.row*2-1] objectForKey:@"name"];
            
            cell.firstLabel.text=firstName;
            
            
            NSString *secondName=[countryListArray[indexPath.row*2] objectForKey:@"name"];
            cell.secondLabel.text=secondName;
            
            
            cell.firstImageview.tag=indexPath.row*2-1;
            cell.secondImageview.tag=indexPath.row*2;
            cell.bgView1.tag=indexPath.row*2-1;
            cell.bgView2.tag=indexPath.row*2;
            cell.firstImageview.delegate=self;
            cell.secondImageview.delegate=self;
            
            UIImage *firstImg=[UIImage imageNamed:[Imagedic objectForKey:firstName]];
            UIImage *scondImg=[UIImage imageNamed:[Imagedic objectForKey:secondName]];
            
            
            cell.firstImageview.frame=CGRectMake(12, 0,firstImg.size.width/2, firstImg.size.height/2);
            cell.secondImageview.frame=CGRectMake(90, 0,firstImg.size.width/2, firstImg.size.height/2);
            cell.firstImageview.image=firstImg;
            cell.secondImageview.image=scondImg;
            
            cell.bgView1.frame=CGRectMake(13/2, 12/2, itemWidth, selectCuntryHeight-6);
            
            CGPoint point1=CGPointMake(cell.bgView1.center.x, cell.bgView1.center.y-10);
            
            cell.firstImageview.center=point1;
            
            cell.bgView1.backgroundColor=[colordic objectForKey:firstName];
            
            cell.bgView2.frame=CGRectMake(12.5+itemWidth, 12/2, itemWidth, selectCuntryHeight-6);
            cell.bgView2.backgroundColor=[colordic objectForKey:secondName];
            
            CGPoint point2=CGPointMake(cell.bgView2.center.x, cell.bgView2.center.y-10);
            
            cell.secondImageview.center=point2;
            
            
            UIGestureRecognizer *tap=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapTheBgbiew:)];
            [cell.bgView1 addGestureRecognizer:tap];
            
            UIGestureRecognizer *tap2=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapTheBgbiew:)];
            [cell.bgView2 addGestureRecognizer:tap2];
            
            return cell;
            
        }
    }else if (tableView==activityTableView)//热点活动
    {
        ActivityTableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];
        
        UIGestureRecognizer *tap=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapActivitysignUp:)];
        [cell.signUpImgview addGestureRecognizer:tap];
        cell.signUpImgview.tag=indexPath.row;
        cell.cellType=CellTypeActivity;
        cell.paramDic=activityArray[indexPath.row];
        cell.selectionStyle=UITableViewCellSelectionStyleNone;
        return cell;
        
    }
    else if(tableView==interViewTableview)//热点面试
    {
        ActivityTableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:@"intervierviewcell" forIndexPath:indexPath];
//        cell.signUpImgview.delegate=self;
        cell.cellType=TypeIterveiw;
        UIGestureRecognizer *tap=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapInterviewSignUp:)];
        [cell.signUpImgview addGestureRecognizer:tap];
        cell.signUpImgview.tag=indexPath.row;

        
        cell.paramDic=interviewArray[indexPath.row];
        cell.selectionStyle=UITableViewCellSelectionStyleNone;
        return cell;

    
    }
    else if (tableView==informationTableview)
    
    {
        ActivityTableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];
        
        if (cell==nil) {
            cell=[[ActivityTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:[NSString stringWithFormat:@"cell"]];
        }
        cell.cellType=CellTypeInfomation;
//        updatetime
        [cell.signUpImgview removeFromSuperview];
        cell.paramDic=informationArray[indexPath.row];
        cell.selectionStyle=UITableViewCellSelectionStyleNone;
       
        return cell;
        
        
    }
    else if (tableView==popTableview)
    {
        SingleImageTableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:@"cell"];
        cell.titleLabel.frame=CGRectMake(0, 0, Mainwidth, 40);
        if (indexPath.row==0) {
             cell.titleLabel.text=@"全部";
        }else{
        cell.titleLabel.text=[popViewData[indexPath.row-1] objectForKey:@"name"];
        }
        cell.titleLabel.textAlignment=NSTextAlignmentCenter;
        cell.backgroundColor=[self getCorlor:@"f5f5f5"];
        return cell;
        
    }
    else{
        
        return nil;
    }
    
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    if (tableView==countryTableview) {
        
        return selectCuntryHeight;
        
    }
    else if (tableView==activityTableView)
    {
        
        return 92;
    }
    else if (tableView==interViewTableview)
    {
        
        return 92;
    }
    else if (tableView==informationTableview)
    {
        
        return 92;
    }
    else if (tableView==popTableview)
    {
        
        return 34;
    }
    else{
        
        return 0;
    }
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (tableView==popTableview)
    {
        if (countryBtn.selected||interviewCountryBtn.selected)
        {
            if (swipIndex==2) {
                interCountryId=indexPath.row;
            }else{
            
            countryId=indexPath.row;
            }
            
            NSString *str;
            
            if (indexPath.row==0) {
               str=[NSString stringWithFormat:@"国家:%@",@"全部"];
            }else{
            
            str=[NSString stringWithFormat:@"国家:%@",[popViewData[indexPath.row-1] objectForKey:@"name"]];
            }
            
           
            NSMutableAttributedString *atts=[[NSMutableAttributedString alloc]initWithString:str];
            [atts addAttributes:@{
                                  NSFontAttributeName:[UIFont systemFontOfSize:12],
                                  NSForegroundColorAttributeName:[self getCorlor:@"888888"],
                                  
                                  
                                  } range:NSMakeRange(0, 3)];
            [atts addAttributes:@{
                                  NSFontAttributeName:[UIFont systemFontOfSize:12],
                                  NSForegroundColorAttributeName:[self getCorlor:@"444444"],
                                  
                                  
                                  } range:NSMakeRange(3, atts.length-3)];
            
            if (swipIndex==2) {
                interviewCountryNameLabel.attributedText=atts;
            }else{
                
                countryNameLabel.attributedText=atts;
            }

            
           
        }else
        {
            if (swipIndex==2) {
                interCityId=indexPath.row;
            }else{
                
                 cityId=indexPath.row;
            }
           
            NSString *str;
            
            if (indexPath.row==0) {
                str=[NSString stringWithFormat:@"分公司:%@",@"全部"];
            }else{
                
                
            
            str=[NSString stringWithFormat:@"分公司:%@",[popViewData[indexPath.row-1]objectForKey:@"name"]];
            }
            NSMutableAttributedString *atts1=[[NSMutableAttributedString alloc]initWithString:str];
            [atts1 addAttributes:@{
                                   NSFontAttributeName:[UIFont systemFontOfSize:12],
                                   NSForegroundColorAttributeName:[self getCorlor:@"888888"],
                                   
                                   
                                   } range:NSMakeRange(0, 4)];
            [atts1 addAttributes:@{
                                   NSFontAttributeName:[UIFont systemFontOfSize:12],
                                   NSForegroundColorAttributeName:[self getCorlor:@"444444"],
                                   
                                   
                                   } range:NSMakeRange(3, atts1.length-3)];
            
            
            if (swipIndex==2) {
                interviewCityName.attributedText=atts1;
            }else{
                
                cityName.attributedText=atts1;
            }

            
          
            
//            [self removeSignUpBgView];
        }
        
        if (swipIndex==2) {
            [self getInterviewData];
            
        }else{
         [self getActivityData];
        }
       
        CGRect framei=popTableview.frame;
        
        CGRect frame2=popTableview.frame;
        framei.origin.y=-framei.size.height;
        
        [UIView animateWithDuration:kInterval animations:^{
            popTableview.frame=framei;
        } completion:^(BOOL finished) {
            [popTableview removeFromSuperview];
            [popviewBg removeFromSuperview];

            popTableview=nil;
            popviewBg=nil;
            countryBtn.selected=NO;
            cityBtn.selected=NO;
            
//            popTableview.frame=frame2;
            interviewCityBtn.selected=NO;
            interviewCountryBtn.selected=NO;
            
        }];
    }else if (tableView==interViewTableview)
    {
        DetailWebViewController *webVc=[[DetailWebViewController alloc]init];
        webVc.ctitle=[interviewArray[indexPath.row] objectForKey:@"title"];
        
        NSString *str=[NSString stringWithFormat:@"http://cent.dsgrd.com/study/lecture/detail?id=%@",[interviewArray[indexPath.row] objectForKey:@"id"]];
        webVc.urlString=str;
        [self.navigationController pushViewController:webVc animated:YES];
    }
    else if (tableView==activityTableView)
    {
        DetailWebViewController *webVc=[[DetailWebViewController alloc]init];
        webVc.ctitle=[activityArray[indexPath.row] objectForKey:@"title"];
        NSString *str=[NSString stringWithFormat:@"http://cent.dsgrd.com/study/activity/detail?id=%@",[activityArray[indexPath.row] objectForKey:@"id"]];
        webVc.urlString=str;
        [self.navigationController pushViewController:webVc animated:YES];
    
    }
    else if (tableView==informationTableview)
    {
    
        DetailWebViewController *webVc=[[DetailWebViewController alloc]init];
        webVc.ctitle=[informationArray[indexPath.row] objectForKey:@"title"];
        webVc.urlString=[NSString stringWithFormat:@"%@news/detail?id=%@",baseUrl,[informationArray[indexPath.row] objectForKey:@"id"]];
        [self.navigationController pushViewController:webVc animated:YES];
    
    }
    else if (tableView==countryTableview)
    {
    
        if (indexPath.row==0) {
            ChooseCountryViewController *chooseVc=[[ChooseCountryViewController alloc]init];
            
            chooseVc.ctitleLabel.text=@"美国留学";
            
            [self.navigationController pushViewController:chooseVc animated:YES];
        }
    
    }
    
}
-(UIView*)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
    if (tableView==popTableview) {
        UIImage *temimg=[UIImage imageNamed:@"shanghua.png"];
//        UIImage *desimg=[self scaleToSize:temimg size:CGSizeMake(Mainwidth, 52)];
        
        
        UIImageView *sectionFooterView=[[UIImageView alloc]initWithFrame:CGRectMake(0, Mainwidth, Mainwidth, temimg.size.height*Mainwidth/temimg.size.width)];
        sectionFooterView.contentMode=UIViewContentModeScaleAspectFit;
        sectionFooterView.image=temimg;
        return sectionFooterView;
    }else{
        return nil;
    }
    
}



-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    if (tableView==popTableview) {
        UIImage *temimg=[UIImage imageNamed:@"shanghua.png"];
        return temimg.size.height*Mainwidth/temimg.size.width;
    }else{
        
        return 0;
    }
    
}








//#pragma mark 选择国家
//
//
//-(void)getCountryList//国家列表
//{
//    [YHNetwork getInformationWithReguestType:RequestTypeGet WithParameters:nil WithApi:@"country" WhenSuccess:^(NSMutableDictionary *response) {
//        countryListArray=response;
//        [countryTableview reloadData];
//    } WhenFailure:^(NSError *failure) {
//        
//    }];
//    
//}
//-(void)getCityList//城市列表
//{
//    
//    [YHNetwork getInformationWithReguestType:RequestTypeGet WithParameters:nil WithApi:@"country" WhenSuccess:^(NSMutableDictionary *response) {
//        cityListArray=response;
//        //        [countryTableview reloadData];
//    } WhenFailure:^(NSError *failure) {
//        
//    }];
//}



-(void)tapActivitysignUp:(UIGestureRecognizer*)index
{
//    //cent.dsgrd.com/study/activity/enter?id=6033
//    //AF_Name=测试&AF_Tel=13107082178&AF_Email=zzw@163.com&AF_City=海淀区&AF_Country=中国
//    
//    
//    
//    
//    NSMutableDictionary *param=[NSMutableDictionary dictionary];
//    [param setObject:@"雷" forKey:@"AF_Name"];
//    [param setObject:@"13107082178" forKey:@"AF_Tel"];
//    [param setObject:@"zzw@163.com" forKey:@"AF_Email"];
//    [param setObject:@"海淀区" forKey:@"AF_City"];
//    [param setObject:@"china" forKey:@"AF_Country"];
//    
//    
//    NSDictionary *dic= activityArray[index.view.tag];
//
// 
//
////
//    [YHNetwork getInformationWithReguestType:RequestTypePost WithParameters:param WithApi:[NSString stringWithFormat:@"study/activity/enter?id=%@",[dic objectForKey:@"id"]] WhenSuccess:^(NSMutableDictionary *response) {
//        
//    } WhenFailure:^(NSError *failure) {
//        
//    }];
    NSDictionary *dic= activityArray[index.view.tag];
    [self addSignUpBgView:TypeActivity SignId:[[dic objectForKey:@"id"] intValue]];
}
-(void)tapInterviewSignUp:(UIGestureRecognizer*)index
{
//    NSMutableDictionary *param=[NSMutableDictionary dictionary];
//    [param setObject:@"浩" forKey:@"AF_Name"];
//    [param setObject:@"13107082178" forKey:@"AF_Tel"];
//    [param setObject:@"zzw@163.com" forKey:@"AF_Email"];
//    [param setObject:@"海淀区" forKey:@"AF_City"];
//    [param setObject:@"china" forKey:@"AF_Country"];
//    
//    
//    NSDictionary *dic= interviewArray[index.view.tag];
//    
////   study/lecture/enter?id=1300
//    
//    [YHNetwork getInformationWithReguestType:RequestTypePost WithParameters:param WithApi:[NSString stringWithFormat:@"study/lecture/enter?id=%@",[dic objectForKey:@"id"]] WhenSuccess:^(NSMutableDictionary *response) {
//        
//    } WhenFailure:^(NSError *failure) {
//        
//    }];
    
    NSDictionary *dic= interviewArray[index.view.tag];
    [self addSignUpBgView:TypeIterveiw SignId:[[dic objectForKey:@"id"] intValue]];
    

}


-(void)addSignUpBgView:(SignUpType)signUpType  SignId:(int)id
{
    
    if (sinUpBgView==nil) {
        sinUpBgView=[[UIView alloc]initWithFrame:self.view.frame];
        sinUpBgView.backgroundColor=[UIColor colorWithRed:0/255.0 green:0/255.0 blue:0/255.0 alpha:0.5];
        
        [self.view addSubview:sinUpBgView];
        
        signUpview=[[SignUpView alloc]initWithFrame:CGRectZero];
        [sinUpBgView addSubview:signUpview];
        

    }
    
    UIGestureRecognizer *tap=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(removeSignUpBgView:)];
    //        [sinUpBgView addGestureRecognizer:tap];
    AppDelegate *ap=  [UIApplication sharedApplication].delegate;
    [ap.window addGestureRecognizer:tap];
    signUpview.signType=signUpType;
    signUpview.signId=id;
//
    
}
-(void)removeSignUpBgView:(UIGestureRecognizer*)tap
{
//    for (NSArray *views in [sinUpBgView subviews]) {
//        
//        
//        
//        for (UIView *temview in views) {
//            [temview removeFromSuperview];
//        }
//    }

    
    
    AppDelegate *ap1=  [UIApplication sharedApplication].delegate;
    [ap1.window removeGestureRecognizer:tap];
    
    if (![[tap.view superview]  isKindOfClass:[SignUpView class]]) {
         sinUpBgView.frame=CGRectMake(0, 0, Mainwidth, 0);
        [sinUpBgView removeFromSuperview];
        sinUpBgView=nil;
    }
    
//    [UIView animateWithDuration:kInterval animations:^{
//        sinUpBgView.frame=CGRectMake(0, 0, Mainwidth, 0);
//    } completion:^(BOOL finished) {
//        [sinUpBgView removeFromSuperview];
//        sinUpBgView=nil;
//    }];
    
  
}
-(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
//consultIndex
    if (scrollView==baseScrollview) {
        int index=floor(scrollView.contentOffset.x)/Mainwidth;
     
        if (swipIndex!=index) {
            UIButton *temBtn=btnArray[swipIndex];
            temBtn.selected=NO;
            swipIndex=index;
            UIButton *temBtn1=btnArray[swipIndex];
            temBtn1.selected=YES;
        }
        consultIndex=index;
        self.requestType=typeDefault;
        
        [self getInfomationData];
        NSLog(@"index==%i",index);
    }
    else{
    
        NSLog(@"tableview");
    
    }
    
    

}

-(void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
{
    if (baseScrollview.contentOffset.x<3*Mainwidth) {
        [self removeMoreCountryView];
        moreBtn.selected=NO;
    }

}
-(void)dealloc
{
    [baseScrollview removeObserver:self forKeyPath:@"contentOffset"];
    

}
@end
